import moment from "moment";
import {TimePicker} from "antd";
import React from "react";
import "./MyTimePicker.css"

function MyTimePicker({initTime, id, getTime, index, disabled, item, timeList}) {

  function translateTimeForCron(momentValue) {
    return momentValue.format('m:H').replaceAll(':', ' ')
  }

  let momentTime
  if (initTime) {
    initTime = initTime.replaceAll(" ", ":")
    momentTime = moment(initTime, 'mm:HH')
  } else {
    momentTime = null
  }
  console.log('renderTime', index)
  return (
    <TimePicker
      disabled={disabled}
      value={momentTime}
      allowClear={false}
      format={'HH:mm'}
      onChange={(value, timeString) => {
        if (value) {
          const timeCron = translateTimeForCron(value)
          getTime({index, id, timeCron, item, timeLi: timeList})
        }
      }}/>
  )
}

export default React.memo(MyTimePicker)

/*
export default React.memo(MyTimePicker, (prevProps, currentProps) => {
  // console.log(prevProps);
  // console.log(nextProps)
  // console.log('function compare', prevProps.getTime == nextProps.getTime)
  // /!*console.log('function compare2', prevProps.getTime.toString() == nextProps.getTime.toString())
  // return prevProps.getTime.toString() != nextProps.toString()*!/
  // // return prevProps.getTime == nextProps.getTime
  let flag = true
  const keys = Object.keys(prevProps).map((key, index) => {
    if (prevProps[key] != currentProps[key]) {
      if (typeof prevProps[key] != 'function') {
        flag = false
      } else {
        flag = prevProps[key].toString() == currentProps[key].toString()
      }
    }
  })
  for (let i = 0; i < keys.length; i++) {

  }
  return flag
})
*/
